var CsOrderPostalComplaintsDatagrid = new HgUi.Datagrid("CsOrderPostalComplaints_datagrid");
CsOrderPostalComplaintsDatagrid.toolbar = $("#CsOrderPostalComplaints_toolbar");
//CsOrderPostalComplaintsDatagrid.mode = "rowEdit"; //行编辑模式
CsOrderPostalComplaintsDatagrid.options.isShowContextMenu = true;
CsOrderPostalComplaintsDatagrid.options.onSelect = function(index,row) {
    if (row && row.dictGroupId){
        CsOrderPostalComplaintsDatagrid.selectedRow = row;
    }
};
CsOrderPostalComplaintsDatagrid.options.onLoadSuccess = function(data) {
    CsOrderPostalComplaintsDatagrid.grid.datagrid("selectRow",0);
};
CsOrderPostalComplaintsDatagrid.init();
//CsOrderPostalComplaintsDatagrid.grid.datagrid("enableFilter");
CsOrderPostalComplaintsDatagrid.bindDefaultToolbarEvent();

// --------------------------保存数据------------------------------------------------------------------
CsOrderPostalComplaintsDatagrid.toolbar.find("[tag=save]").click(function() {
    if (CsOrderPostalComplaintsDatagrid.isEditing == true) {
        if (CsOrderPostalComplaintsDatagrid.grid.datagrid("validateRow", CsOrderPostalComplaintsDatagrid.editingIndex)) {
            var data = CsOrderPostalComplaintsDatagrid.makeSubmitData();
            var editRow = CsOrderPostalComplaintsDatagrid.grid.datagrid("getRows")[CsOrderPostalComplaintsDatagrid.editingIndex];
            var submitUrl = "/cs/CsOrderPostalComplaints/add";
            if (editRow.id) {
                submitUrl = "/cs/CsOrderPostalComplaints/upd";
                data.id = editRow.id;
            }
            HgUtil.post(submitUrl, data, function(data) {
                if (!data.success) {
                    CsOrderPostalComplaintsDatagrid.showMsgbox("error", data.data, 330);
                } else {
                    CsOrderPostalComplaintsDatagrid.grid.datagrid('reload');
                }
            });

        } else {
            CsOrderPostalComplaintsDatagrid.showMsgbox("alert", "有一条数据未校验通过!", 180);
        }
    }
});

//-------------------------删除-----------------------------------------------------------------------
CsOrderPostalComplaintsDatagrid.toolbar.find("[tag=del]").click(function(){
    var row = CsOrderPostalComplaintsDatagrid.grid.datagrid("getSelected");
    if (!row) {
        $.messager.alert("提示","请选择一条字典组数据","warning");
        return;
    }
    $.messager.confirm("确认删除", "确认将选中的字典组删除?", function(r){
        if (r) {
            HgUtil.getJson("/cs/CsOrderPostalComplaints/del",{id:row.id}, function(data){
                if (!data.success) {
                    $.messager.alert("提示","删除失败,"+data.data,"warning");
                } else {
                    HgUi.ok("删除成功!",function(){
                        CsOrderPostalComplaintsDatagrid.grid.datagrid("reload");
                    });
                }
            });
        }
    });
});

// 组织提交数据
CsOrderPostalComplaintsDatagrid.makeSubmitData = function() {
    var postalComplaintsCode = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "postalComplaintsCode"
    });
    var complainant = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainant"
    });
    var complainantTel = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainantTel"
    });
    var waybillNum = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "waybillNum"
    });
    var complainTime = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainTime"
    });
    var pab = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "pab"
    });
    var pabProvince = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "pabProvince"
    });
    var pabDate = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "pabDate"
    });
    var pabNum = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "pabNum"
    });
    var complainType = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainType"
    });
    var complainReason = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainReason"
    });
    var complainContent = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "complainContent"
    });
    var handler = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "handler"
    });
    var handleTime = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "handleTime"
    });
    var satisficing = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "satisficing"
    });
    var deadline = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "deadline"
    });
    var closingTime = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "closingTime"
    });
    var duration = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "duration"
    });
    var isTimeout = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "isTimeout"
    });
    var timeoutDuration = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "timeoutDuration"
    });
    var orderStatus = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "orderStatus"
    });
    var isValid = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "isValid"
    });
    var countryVerdictResult = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "countryVerdictResult"
    });
    var lastVerdictResult = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "lastVerdictResult"
    });
    var dutyAnalyze = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "dutyAnalyze"
    });
    var dutyAttribution = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "dutyAttribution"
    });
    var processinstId = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "processinstId"
    });
    var qualityControl = CsOrderPostalComplaintsDatagrid.grid.datagrid('getEditor', {
        index : CsOrderPostalComplaintsDatagrid.editingIndex,
        field : "qualityControl"
    });

    var data = {
        postalComplaintsCode : $(postalComplaintsCode.target).textbox("getValue"),
        complainant : $(complainant.target).textbox("getValue"),
        complainantTel : $(complainantTel.target).textbox("getValue"),
        waybillNum : $(waybillNum.target).textbox("getValue"),
        complainTime : $(complainTime.target).textbox("getValue"),
        pab : $(pab.target).textbox("getValue"),
        pabProvince : $(pabProvince.target).textbox("getValue"),
        pabDate : $(pabDate.target).textbox("getValue"),
        pabNum : $(pabNum.target).textbox("getValue"),
        complainType : $(complainType.target).textbox("getValue"),
        complainReason : $(complainReason.target).textbox("getValue"),
        complainContent : $(complainContent.target).textbox("getValue"),
        handler : $(handler.target).textbox("getValue"),
        handleTime : $(handleTime.target).textbox("getValue"),
        satisficing : $(satisficing.target).textbox("getValue"),
        deadline : $(deadline.target).textbox("getValue"),
        closingTime : $(closingTime.target).textbox("getValue"),
        duration : $(duration.target).textbox("getValue"),
        isTimeout : $(isTimeout.target).textbox("getValue"),
        timeoutDuration : $(timeoutDuration.target).textbox("getValue"),
        orderStatus : $(orderStatus.target).textbox("getValue"),
        isValid : $(isValid.target).textbox("getValue"),
        countryVerdictResult : $(countryVerdictResult.target).textbox("getValue"),
        lastVerdictResult : $(lastVerdictResult.target).textbox("getValue"),
        dutyAnalyze : $(dutyAnalyze.target).textbox("getValue"),
        dutyAttribution : $(dutyAttribution.target).textbox("getValue"),
        processinstId : $(processinstId.target).textbox("getValue"),
        qualityControl : $(qualityControl.target).textbox("getValue")
    };
    return data;
};
//查询------------------------------------------------------------------------------------------------------
CsOrderPostalComplaintsDatagrid.toolbar.find("[tag=submit]").click(function(){
	var searchData = {};
	searchData["postalComplaintsCode"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=postalComplaintsCode]").val());
	searchData["waybillNum"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=waybillNum]").val());
	searchData["complainType"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=complainType]").val());
	searchData["orderStatus"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=orderStatus]").val());
	searchData["complainantTel"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=complainantTel]").val());
	searchData["staffInfo.bo.entryEndTime"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=endTime]").val());
	searchData["handler"] =  $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=handler]").val());
	searchData["userPosition.positionName"] = $.trim(CsOrderPostalComplaintsDatagrid.toolbar.find("[name=positionName]").val());
	searchData=HgUtil.paramMapTrim(searchData);
	CsOrderPostalComplaintsDatagrid.grid.datagrid('load',searchData);
});
// 清空查询---------------------------------------------------------------------------------------------------
CsOrderPostalComplaintsDatagrid.toolbar.find("[tag=clear]").click(function() {
    CsOrderPostalComplaintsDatagrid.grid.datagrid("removeFilterRule");
    CsOrderPostalComplaintsDatagrid.grid.datagrid("load", {});
});
